define(["moment"], function (moment) {
	return ["$scope", "$filter", "$stateParams", "config", "MMWService", "$mdDialog", "$timeout",
		function ($scope, $filter, $stateParams, config, $MMWService, $mdDialog, $timeout) {
			$scope.init = function () {
				//每隻程式都有，等於window.onload方法
				$scope.C00_require_condition = true;
				var datasource_format_info = {};
				datasource_format_info.iselectd_filed = "1";
				$scope.mode = "query";
				$scope.codeList = [
					{ name: $filter('translate')('IIoT0107.conditionType.type_1'), column_name: 'A.WORKDATE', data_type: 'SE', date_forward: true },
					{ name: $filter('translate')('IIoT0107.conditionType.type_2'), column_name: 'E.AREANO' },
					{ name: $filter('translate')('IIoT0107.conditionType.type_3'), column_name: 'E.AREANAME' },
					{ name: $filter('translate')('IIoT0107.conditionType.type_4'), column_name: 'A.EQUIPMENTNO' },
					{ name: $filter('translate')('IIoT0107.conditionType.type_5'), column_name: 'C.EquipmentName' },
					{ name: $filter('translate')('IIoT0107.conditionType.type_6'), column_name: 'F.OPNO' },
					{ name: $filter('translate')('IIoT0107.conditionType.type_7'), column_name: 'F.OPNAME' }
				];
				$scope.equipment_dispatch_loading_info = [];
			}
			$scope.back = function () {
				//返回首頁，傳入true表示使用退出
				$scope.$root.hideMenu();
				$scope.$root.changeProgram('home', true);//動畫
			}

			$scope.chagnge_dis_work_date = function (eq_item, event) {
				//確認按鈕
				$mdDialog.serviceDialog('IIoT0108_Service', eq_item, function (dialog) {
					if (dialog.is_confirm) {
						$timeout(function () {
							$scope.init();
							var condition = $scope.$root.genConditioninfo();
							$scope.search(condition);
						}, 1000);
					}
				});
			}
			$scope.get_loading_state_class = function (loading_state) {
				var str = "load_state_green";
				switch (loading_state) {
					case "1":
						str = "load_state_red"
						break;
					case "2":
						str = "load_state_yellow"
						break;
					case "3":
						str = "load_state_green"
						break;
				}
				return str;
			}
			$scope.get_equipment_state_class = function (equipment_state) {
				var str = "equipment_status_";
				str += equipment_state;
				return str;
			}
			$scope.search = function (condition) {
				if (condition.length > 0) {
					var content = {};
					content.query_condition = condition;
					$MMWService.sendToServer({
						uri: 'ServicesSTD.Module_IIoT.equipment_dispatch_loading_info_get',
						content: content,
						success: function (data) {
							if (data.equipment_dispatch_loading_info) {
								$scope.equipment_dispatch_loading_info = data.equipment_dispatch_loading_info;
								for (var i in $scope.equipment_dispatch_loading_info) {
									$scope.equipment_dispatch_loading_info[i].work_date = moment($scope.equipment_dispatch_loading_info[i].work_date).format('YYYY-MM-DD');
								}
							}
						}
					});
				}
			}
		}
	]
});